package lease

import "testing"

func TestAmILeader(t *testing.T) {
	defer SetMeWithoutStatus()

	SetMeLeader()
	if lease != Leader {
		t.Fatal("Lease should be leader but lease is ", lease)
	}

	if !AmILeader() || AmISlave() || !DoesLeaseStatusSet() {
		t.Fatalf("Wrong answer, i am leader")
	}

	SetMeSlave()
	if lease != Slave {
		t.Fatal("Lease should be slave but lease is ", lease)
	}

	if !AmISlave() || AmILeader() || !DoesLeaseStatusSet() {
		t.Fatal("Wrong answer, i am slave")
	}

	SetMeWithoutStatus()
	if lease != NotSet {
		t.Fatal("Lease is not set but lease is ", lease)
	}

	if DoesLeaseStatusSet() || AmILeader() || AmISlave() {
		t.Fatal("Wrong answer, lease status not set")
	}
}
